#!/bin/bash
source $DRAW_INI
source $DRAW_CFG

mkdir -p ../csv

NAME=$(basename $1)
RFILE="../csv/$NAME.snp.recal"
TFILE="../csv/$NAME.snp.tranches"


java -Xmx4g -jar $GATK \
  -T VariantRecalibrator \
  -R $REF_FASTA \
   --maxGaussians 6 \
   -resource:hapmap,known=false,training=true,truth=true,prior=15.0 $BUNDLE_HAPMAP \
   -resource:omni,known=false,training=true,truth=false,prior=12.0 $BUNDLE_OMNI \
   -resource:dbsnp,known=true,training=false,truth=false,prior=6.0 $SNPDB \
   -an QD -an HaplotypeScore -an MQRankSum -an ReadPosRankSum -an FS -an MQ \
   -mode SNP \
   -input $1.vcf \
   -recalFile $RFILE \
   -tranchesFile $TFILE
     
EXITSTATUS=$?

#   -an QD -an HaplotypeScore -an MQRankSum -an ReadPosRankSum -an FS -an MQ -an InbreedingCoeff \

#force error when missing recalFile. Would prevent continutation of pipeline
if [[ ! -s "$RFILE" || ! -s "$TFILE" ]];
then
 echo "Missing $RFILE or $TFILE in ../csv" 
 exit 100
fi

exit $EXITSTATUS
